from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

driver.get("http://www.baidu.com")

# 元素定位
# 通过xpath对id进行定位
# driver.find_element(By.XPATH, "//*[@id='kw']").send_keys("xpath")
# driver.find_element(By.XPATH, "//*[@name='']").send_keys("xpath")
# driver.find_element(By.XPATH, "//*[@class='s_ipt']").send_keys("xpath")

# 层级
# //from[@id="from"]/span/input 通过层级定位百度首页输入框
# input_tag = driver.find_element(By.XPATH, "//form[@id='form']/input")
# print(input_tag.get_attribute('outerHTML'))

# 层级+索引
input_tag = driver.find_element(By.XPATH, "//form[@id='form']/input[8]")
print(input_tag.get_attribute("outerHTML"))


driver.quit()
